package com.zh.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zh.common.Result;
import com.zh.pojo.State;
import com.zh.pojo.vo.StateVo;
import com.zh.service.StateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 统计
 * @ClassName StateController
 * @date: 2021.05.10 14:34
 * @Author: zhanghang
 */
@Controller
public class StateController {

    @Autowired
    private StateService stateService;

    /**
     * description: 根据统计主题id，获取统计的具体项
     * date: 2021年-05月-11日 9:30
     * author: zhanghang
     * 
     * @param id
     * @return com.zh.common.Result<?>
     */ 
    @GetMapping("/state/{id}")
    public String getStates(@PathVariable("id") Integer id, ModelMap modelMap){
        State state = stateService.getById(id);
        if (null == state){
            return "redirect:/error";
        }
        modelMap.put("result",stateService.getStatesById(id));
        modelMap.put("id",id);
        return "state/detail";
    }

    @GetMapping("/state/detail")
    @ResponseBody
    public Result<?> getStatesDEtail(@RequestParam("id") Integer id){
        if (null == id){
            return Result.error("入参不完整");
        }

        return stateService.getStatesById(id);
    }

    @GetMapping("/state/save")
    public Result<?> stateSave(){
        State state = new State();
        state.setTitle("123456");
        stateService.save(state);
        return Result.ok();
    }

    @GetMapping("/state/update")
    public Result<?> stateUpdate(){
        State state = new State();
        state.setId(2);
        state.setTitle("123456");
        stateService.updateById(state);
        return Result.ok();
    }
}
